<?php
$dbFile = 'cms.db';
$pdo = new PDO('sqlite:' . $dbFile);

// 检查请求是否包含 ID
if (isset($_GET['id'])) {
    $id = $_GET['id'];

    // 更新点赞数
    $stmt = $pdo->prepare("UPDATE posts SET likes = likes + 1 WHERE id = ?");
    $stmt->execute([$id]);

    // 获取新的点赞数
    $stmt = $pdo->prepare("SELECT likes FROM posts WHERE id = ?");
    $stmt->execute([$id]);
    $likes = $stmt->fetchColumn();

    // 返回 JSON 格式的数据
    echo json_encode(['success' => true, 'likes' => $likes]);
} else {
    echo json_encode(['success' => false]);
}
